package me.sunpeng.design.singleton.type6;

/**
 * @author sp
 */
public class SingletonTest06 {
    public static void main(String[] args) {

    }
}

//懒汉式(线程安全，同步代码块，双重检查)
class Singleton {
    private static volatile Singleton instance;

    private Singleton() {

    }
    //提供一个静态的共有方法，加入双重检查代码，解决线程安全问题和懒加载问题
    //保证了效率问题
    public static  Singleton getInstance(){
        if (instance == null){
            synchronized (Singleton.class){
                if (instance == null){
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }

}
